package com.linkhub.oms.common.enums.mp;

import com.linkhub.oms.common.enums.IEnumConvert;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import java.util.Objects;

/**
 * 币种
 *
 * @author Franck
 */
@Getter
@AllArgsConstructor
public enum CurrencyTypeEnum implements IEnumConvert<Integer> {
    /**
     * 币种，不可随意修改typeStr
     */
    EUR(1, "EUR", "EUR - Euro"),
    GBP(2, "GBP", "GBP - Great British Pound"),
    CAD(3, "CAD", "CAD - Canadian dollar"),
    USD(4, "USD", "USD - United States Dollar"),
    AUD(5, "AUD", "AUD - Australian Dollar"),
    RMB(6, "RMB", "RMB");

    private final Integer type;
    private final String typeStr;
    private final String desc;


    @Override
    public Integer getCode() {
        return this.type;
    }


    public static CurrencyTypeEnum getByType(Integer type) {
        if (Objects.isNull(type)) {
            return null;
        }
        for (CurrencyTypeEnum currencyTypeEnum : CurrencyTypeEnum.values()) {
            if (currencyTypeEnum.type.equals(type)) {
                return currencyTypeEnum;
            }
        }
        return null;
    }

    public static String getTypeStrByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return null;
        }
        for (CurrencyTypeEnum currencyTypeEnum : CurrencyTypeEnum.values()) {
            if (desc.startsWith(currencyTypeEnum.getTypeStr())) {
                return currencyTypeEnum.getTypeStr();
            }
        }
        return null;
    }

    // 获取所有typeStr的
    public static List<String> getAllTypeStr() {
        return Stream.of(CurrencyTypeEnum.values())
                .map(CurrencyTypeEnum::getTypeStr)
                .collect(Collectors.toList());
    }

}
